<template>
  <div>
    <list-page :data="listPageConfig">
      <template v-slot:tableColumn>
        <el-table-column
          align="center"
          label="季度"
          prop="addTime"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          label="姓名"
          prop="addTime"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          label="上传时间"
          prop="addTime"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          label="状态"
          prop="status_title"
          show-overflow-tooltip
        />
        <el-table-column
          align="center"
          label="分数"
          prop="orgPostUserWorkSumScore_score"
          show-overflow-tooltip
        />
        <el-table-column align="center" label="操作">
          <template v-slot="{ row }">
            <el-button
              v-if="row.status == 1"
              type="text"
              size="small"
              @click="submitJobSummary(row)"
              >提交工作小结</el-button
            >
            <el-button
              v-else-if="row.status == 2"
              type="text"
              size="small"
              @click="updateSum(row)"
              >撤销提交</el-button
            >
          </template>
        </el-table-column>
      </template>
    </list-page>
    <edit-dialog v-model="editDialog" @success="success" />
  </div>
</template>

<script>
import tableMixin from '@/mixin/tablePageMixin'
import ListPage from '@/views/_common/ListPage'
import EditDialog from './components/EditDialog'
import { request } from '@/api/request'

export default {
  name: 'JobSummary',

  components: {
    ListPage,
    EditDialog
  },

  mixins: [tableMixin],

  data: () => ({
    editDialog: false,
    currentId: null
  }),

  computed: {
    listPageConfig() {
      return {
        pageLoading: this.config.operating,
        dataLoading: this.config.loading,
        buttons: [],
        table: {
          props: { data: this.tableData },
          on: { 'row-click': this.rowClick }
        },
        pagination: {
          props: { model: this.searchForm },
          on: {
            'current-change': this.pageChange,
            'size-change': this.pageSizeChange
          }
        }
      }
    }
  },

  methods: {
    submitJobSummary() {
      this.editDialog = true
    },

    success() {
      this.tableData[0].status = 2
      // this.search()
    },

    search() {
      if (this.config.loading) return
      this.config.loading = true
      request(
        'personal/myWorkSummary/index',
        { p: this.searchForm.page, limit: this.searchForm.pageSize },
        (res) => {
          this.searchForm.total = res.data.count
          this.tableData = res.data._list
        }
      ).finally(() => {
        this.tableData = [
          {
            status: 1,
            status_title: '待上传'
          }
        ]
        this.config.loading = false
      })
    }
  }
}
</script>
